package com.team.ai.service;

import cn.hutool.core.date.DateTime;
import com.team.ai.entity.ResultEntity;
import com.team.ai.mapper.CommentsMapper;
import com.team.ai.mapper.CommunityMapper;
import com.team.ai.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class CommentsServive {
    @Resource
    CommentsMapper commentsMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    CommunityMapper communityMapper;
    public String insert(int userId,int communityId,String comments,String uName,String pic){
        try{
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date now = DateTime.now();
            String dateStr = sdf.format(now);
            Date date = sdf.parse(dateStr);
            System.out.println(now);
            return ResultEntity.success(commentsMapper.insert(userId,communityId,comments,uName,pic,date)) ;
        }catch (Exception e){
            e.printStackTrace();

            return  ResultEntity.fail(-10005);
        }
    }
    public String selectList(){
        try{

            return ResultEntity.success(commentsMapper.selectList()) ;
        }catch (Exception e){
            e.printStackTrace();

            return  ResultEntity.fail(-10005);
        }
    }

    public String selectLists(int communityId){
        try{

            return ResultEntity.success(commentsMapper.selectLists(communityId)) ;
        }catch (Exception e){
            e.printStackTrace();

            return  ResultEntity.fail(-10005);
        }
    }
}
